package com.zlq.cn.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zlq.cn.api.SignApiResult;
import com.zlq.cn.dto.vo.TianListResult;
import com.zlq.cn.entity.TianDataSave;
import com.zlq.cn.entity.TianStarinfo;
import com.zlq.cn.service.tian.TianConfigService;
import com.zlq.cn.service.tian.TianDataSaveService;
import com.zlq.cn.service.tian.TianService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;

@Slf4j
@Api(tags = "公共-天行数据")
@RestController
@AllArgsConstructor
@Validated
@RequestMapping("/api/common/tian")
public class TianApiController extends BaseController {

    @Resource
    private TianService tianService;

    @Resource
    private TianConfigService.TianApiService tianApiService;

    @Resource
    private TianDataSaveService tianDataSaveService;

    @SneakyThrows
    @ApiOperation("经典台词")
    @GetMapping("/dialogue")
    public SignApiResult<JSONObject> dialogue() {
        return SignApiResult.resultSuccess(tianApiService.dialogue().execute().body().getResult());
    }

    @ApiOperation("明星百科大全")
    @GetMapping("/starinfo")
    public SignApiResult<List<TianStarinfo>> starinfo(@Valid TianStarinfo param) {
        return SignApiResult.resultSuccess(tianService.starinfo(param));
    }

    @ApiOperation(value = "明星百科大全已有列表", notes = "注意必须带上分页参数；current、size")
    @GetMapping("/starinfo/list")
    public SignApiResult<Page<TianStarinfo>> list(@ApiIgnore TianStarinfo param) {
        return SignApiResult.resultSuccess(tianService.starinfoList(super.getPage(), param));
    }

    @ApiOperation(value = "天行数据列表", notes = "注意必须带上分页参数；current、size")
    @ApiImplicitParam(name = "type", value = "数据类型，就是接口名称比如彩虹屁就是：caihongpi", paramType = "query", required = true)
    @GetMapping("/tian/list")
    public SignApiResult<Page<TianDataSave>> tianList(@ApiIgnore TianDataSave tianDataSave) {
        return SignApiResult.resultSuccess(tianDataSaveService.lambdaQuery()
                .eq(TianDataSave::getType, tianDataSave.getType())
                .page(super.getPage()));
    }

    @SneakyThrows
    @ApiOperation("所有公共接口")
    @ApiImplicitParam(name = "apiNo", value = "数据类型，就是接口名称比如彩虹屁就是：caihongpi", paramType = "query", required = true)
    @GetMapping("/common/api")
    public SignApiResult<Object> tianCommonApi(String apiNo, @ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.tianCommonApi(apiNo, TianConfigService.paramConvert(param)).execute().body().getResult());
    }

    @SneakyThrows
    @ApiOperation("神回复")
    @GetMapping("/godreply")
    public SignApiResult<List<JSONObject>> godreply(@ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.godreply(TianConfigService.paramConvert(param)).execute().body().getResult().getList());
    }

    @SneakyThrows
    @ApiOperation("歇后语")
    @GetMapping("/xiehou")
    public SignApiResult<List<JSONObject>> xiehou(@ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.xiehou(TianConfigService.paramConvert(param)).execute().body().getResult().getList());
    }

    @SneakyThrows
    @ApiOperation("脑筋急转弯")
    @GetMapping("/naowan")
    public SignApiResult<List<JSONObject>> naowan(@ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.naowan(TianConfigService.paramConvert(param)).execute().body().getResult().getList());
    }

    @SneakyThrows
    @ApiOperation("网络流行语")
    @GetMapping("/hotword")
    public SignApiResult<TianListResult<JSONObject>> hotword(@ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.hotword(TianConfigService.paramConvert(param)).execute().body().getResult());
    }

    @SneakyThrows
    @ApiOperation("雷人笑话")
    @GetMapping("/joke")
    public SignApiResult<List<JSONObject>> joke(@ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.joke(TianConfigService.paramConvert(param)).execute().body().getResult().getList());
    }

    @SneakyThrows
    @ApiOperation("朋友圈文案")
    @GetMapping("/pyqwenan")
    public SignApiResult<JSONObject> pyqwenan(@ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.pyqwenan(TianConfigService.paramConvert(param)).execute().body().getResult());
    }

    @SneakyThrows
    @ApiOperation("失恋分手句子")
    @GetMapping("/hsjz")
    public SignApiResult<JSONObject> hsjz(@ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.hsjz(TianConfigService.paramConvert(param)).execute().body().getResult());
    }

    @SneakyThrows
    @ApiOperation("彩虹屁")
    @GetMapping("/caihongpi")
    public SignApiResult<JSONObject> caihongpi(@ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.caihongpi(TianConfigService.paramConvert(param)).execute().body().getResult());
    }

    @SneakyThrows
    @ApiOperation("舔狗日记")
    @GetMapping("/tiangou")
    public SignApiResult<JSONObject> tiangou(@ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.tiangou(TianConfigService.paramConvert(param)).execute().body().getResult());
    }

    @SneakyThrows
    @ApiOperation("早安心语")
    @GetMapping("/zaoan")
    public SignApiResult<JSONObject> zaoan(@ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.zaoan(TianConfigService.paramConvert(param)).execute().body().getResult());
    }

    @SneakyThrows
    @ApiOperation("早安心语")
    @GetMapping("/wanan")
    public SignApiResult<JSONObject> wanan(@ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.wanan(TianConfigService.paramConvert(param)).execute().body().getResult());
    }

    @SneakyThrows
    @ApiOperation("毒鸡汤")
    @GetMapping("/dujitang")
    public SignApiResult<JSONObject> dujitang(@ApiIgnore @RequestParam HashMap<String, Object> param) {
        return SignApiResult.resultSuccess(tianApiService.dujitang(TianConfigService.paramConvert(param)).execute().body().getResult());
    }
}
